package com.hmall.gateway.filters;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PrintAnyGatewayFilterFactory extends AbstractGatewayFilterFactory<PrintAnyGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(Config config) {
        return (exchange, chain) ->
        {
            ServerHttpRequest request = exchange.getRequest();
            System.out.println("自定义过滤器执行了");
            String a = config.getA();
            String b = config.getB();
            String c = config.getC();
            System.out.println("Pararmc = " + c);
            System.out.println("Pararmb = " + b);
            System.out.println("Pararma = " + a);

            return chain.filter(exchange);
        };
    }



    @Data
    public static class Config{
        private String a;
        private String b;
        private String c;
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return List.of("a","b","c");
    }

    @Override
    public Class<Config> getConfigClass() {
        return Config.class;
    }

}
